package com.yc.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yc.entity.Product;
import com.yc.mapper.ProductMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * InnoDB free: 5120 kB; (`csid`) REFER `test/categorysecond`(`csid`); (`csid`) REF 前端控制器
 * </p>
 *
 * @author ly
 * @since 2022-05-08
 */
@Controller
@RequestMapping("//product")
public class ProductController {
    @Resource
    private ProductMapper productMapper;

    @RequestMapping("get.do")
    @ResponseBody
    public Product selectById(int id){
        return productMapper.selectById(id);
    }

    @RequestMapping("new.do")
    @ResponseBody
    public List<Product> querynewproduct(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.orderByDesc("pdate");
        queryWrapper.last(" limit 10");
        List list=productMapper.selectList(queryWrapper);
        return list;
    }

    @RequestMapping("hot.do")
    @ResponseBody
    public List<Product> queryhotproduct(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("is_hot",1);
        queryWrapper.last(" limit 10");
        List list=productMapper.selectList(queryWrapper);
        return list;
    }

    @RequestMapping("queryByCsid")
    @ResponseBody
    public List<Product> queryByCsid(int csid){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("csid",csid);
        List<Product> list=productMapper.selectList(queryWrapper);
        return list;
    }

    @RequestMapping("queryByCid")
    @ResponseBody
    public List<Product> queryByCid(int cid){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.inSql("csid","select csid from categorysecond where cid="+cid);
        List<Product> list=productMapper.selectList(queryWrapper);
        return list;
    }
}

